﻿using Dapper;
using System.Collections.Generic;
using System.Data;

namespace BCData.TMS
{
    /// <summary>
    /// 拼接查询条件
    /// </summary>
    public static class SplicingCondition
    {
        /// <summary>
        /// 拼接默认查询条件
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="currentControlId">当前控制Id</param>
        /// <param name="isOperationQuery">是否作业查询</param>
        /// <param name="currentCompanyLevel">当前公司级别</param>
        /// <param name="fenceId">围栏Id</param>
        /// <param name="wheres">返回查询条件</param>
        /// <param name="parameters">返回查询条件参数列表</param>
        public static void DefaultConditionFileds(string tableName, int? currentControlId, bool? isOperationQuery, int? currentCompanyLevel, int? fenceId, ref List<string> wheres, ref DynamicParameters parameters)
        {
            if (currentControlId.HasValue)
            {
                wheres.Add($"{tableName}.CompanyId=?CompanyId");
                parameters.Add("?CompanyId", currentControlId.Value, DbType.Int32);
            }
            if (isOperationQuery.HasValue)
            {
                if (isOperationQuery.Value)
                {
                    wheres.Add($"{tableName}.CompanyId=?CompanyId");
                    parameters.Add("?CompanyId", currentControlId.Value, DbType.Int32);
                }
                else
                {
                    wheres.Add($"{tableName}.CurrentCompanyLevel=?CurrentCompanyLevel");
                    parameters.Add("?CurrentCompanyLevel", currentCompanyLevel.Value, DbType.Int32);
                }
            }
            else
            {
                //总部查询
            }
            if (currentCompanyLevel.HasValue)
            {
                wheres.Add($"{tableName}.CurrentCompanyLevel=?CurrentCompanyLevel");
                parameters.Add("?CurrentCompanyLevel", currentCompanyLevel.Value, DbType.Int32);
            }
            if (fenceId.HasValue)
            {
                wheres.Add($"{tableName}.FenceId=?FenceId");
                parameters.Add("?FenceId", fenceId.Value, DbType.Int32);
            }
        }

    }
}
